package view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;

/**
 * Created by ilioili on 2015/3/24.
 */
public class MyFrameLayout extends FrameLayout {
    public MyFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setPosition(int position) {
        if (position >= getChildAt(1).getMeasuredHeight()) {
            //            ViewGroup v = (ViewGroup) getChildAt(0);
            //            float alpha = (1f*position-getChildAt(0).getMeasuredHeight())/getChildAt(1).getMeasuredHeight();
            //            for(int i=0; i<v.getChildCount(); i++){
            //                v.getChildAt(i).setAlpha(alpha);
            //            }
            //            getChildAt(1).setAlpha((1f*position-getChildAt(0).getMeasuredHeight())/getChildAt(1).getMeasuredHeight());
            int t = position - getChildAt(1).getMeasuredHeight();
            getChildAt(1).layout(0, t, getMeasuredWidth(), position);
            getChildAt(0).layout(0, t - getChildAt(0).getMeasuredHeight(), getMeasuredWidth(), t);
        } else {
            getChildAt(1).layout(0, 0, getMeasuredWidth(), getChildAt(1).getMeasuredHeight());
        }
        invalidate();

    }
}
